﻿(function (doc, win) {
    var docEl = doc.documentElement,
        resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize',
        recalc = function () {
            var clientWidth = docEl.clientWidth;
            if (!clientWidth) return;
            docEl.style.fontSize = 100 * (clientWidth / 720) + 'px';
        };
    // Abort if browser does not support addEventListener
    if (!doc.addEventListener) return;
    win.addEventListener(resizeEvt, recalc, false);
    doc.addEventListener('DOMContentLoaded', recalc, false);
})(document, window);

/**
 * 设置购物车数量 
 */
function doSetShopCount(count) {
	if (count) {
		$("#shopCount").html(parseInt(count) > 99 ? "99+" : count);
	}
}

/**
 * 获取购物车数量
 */
function doGetShopCount() {
	/**
	 * 获取购物车数量
	 */
	$.ajax({
		type: 'POST',
		url: rootPath + "/wx/shoppingcart/getShoppingcarCount",
		async: true,
		dataType: 'json',
		success: function(json) {
			if(json.resultCode == '1') {
				if(parseInt(json.count) > 0) {
					$("#shopCount").show();
					$("#shopCount").html(parseInt(json.count) > 99 ?  "99+" : json.count);
				} else {
					$("#shopCount").hide();
					$("#shopCount").html('');
				}
				
			}
		}
	});
}

/**
 * 显示提示信息 
 */
function showMsg(msg) {
	var $msg = 
		$('<div class="reg_tips" style="display: block">' + 
		  '	<p>'+msg+'</p>' +
		  '</div>'
		);
	$(document.body).append($msg);
	delay = 3000; //3s
	window.setTimeout(function(){
		$msg.remove();
	}, delay)
}

/**
 * 显示成功提示信息 
 */
function showSuccess(msg) {
	var successInfo = msg || "操作成功";
	var $msg = 
		$('<div class="reg_tips2" style="display: block">' + 
		  '	<p><i></i>'+successInfo+'</p>' +
		  '</div>'
		);
	$(document.body).append($msg);
	delay = 3000; //3s
	window.setTimeout(function(){
		$msg.remove();
	}, delay)
}

/**
 * 显示失败提示信息 
 */
function showError(msg) {
	var errorInfo = msg || "操作失败";
	var $msg = 
		$('<div class="reg_tips2" style="display: block">' + 
		  '	<p><i class="a1"></i> <span>'+errorInfo+'</span></p>' +
		  '</div>'
		);
	$(document.body).append($msg);
	delay = 3000; //3s
	window.setTimeout(function(){
		$msg.remove();
	}, delay)
}
